001 /*
002 * Copyright (c) 2005 Stephen J. McConnell
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.component;
020
021 import java.net.URI;
022
023 /**
024 * Exception thrown when an attempt is made to reference an unknown part.
025 *
026 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
027 * @version 1.0.2
028 */
029 public class PartNotFoundException extends ControlException
030 {
031 /**
032 * Serial version identifier.
033 */
034 static final long serialVersionUID = 1L;
035
036 private URI m_target;
037 private URI m_parent;
038
039 /**
040 * Creation of a new <tt>PartNotFoundException</tt>.
041 * @param uri the controller uri
042 * @param target the target part
043 */
044 public PartNotFoundException( URI uri, URI target )
045 {
046 this( uri, target, null );
047 }
048
049 /**
050 * Creation of a new <tt>PartNotFoundException</tt>.
051 * @param uri the controller uri
052 * @param parent the parent part
053 * @param target the target part
054 */
055 public PartNotFoundException( URI uri, URI parent, URI target )
056 {
057 super( uri, buildMessage( parent, target ) );
058 m_target = target;
059 m_parent = parent;
060 }
061
062 /**
063 * Return the parent part.
064 * @return the uri of the part in which the sub-part request was raised
065 */
066 public URI getParentURI()
067 {
068 return m_parent;
069 }
070
071 /**
072 * Return the target part uri.
073 * @return the uri of the target part
074 */
075 public URI getTargetURI()
076 {
077 return m_target;
078 }
079
080 private static String buildMessage( URI parent, URI target )
081 {
082 if( null != parent )
083 {
084 final String error =
085 "Could not find the a part uri ["
086 + target
087 + "] relative to the enclosing part ["
088 + parent.toString()
089 + "].";
090 return error;
091 }
092 else
093 {
094 final String error =
095 "Could not find a part ["
096 + target
097 + "].";
098 return error;
099 }
100 }
101
102 }
103